/*
Copyright 2010 Christian Dadswell
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package subscriber.chrisdadswell.co.uk;

import java.util.logging.Handler;

import android.util.Log;

public class Thread_FindFeed extends Thread {
	
	// PUBLIC CONSTANTS
	public static final String _APP_TAG = "SUBSCRIBER";
	public static final String _ACT_TAG = "Thread_FindFeed";
	
	public final static byte STATE_NOT_STARTED = 0;
	public final static byte STATE_RUNNING = 1;
	public final static byte STATE_DONE = 2;
	
	public final static int MESSAGE_COMPLETE = 0;
	public final static int MESSAGE_ERROR = 1;
	public final static int MESSAGE_PROGRESS = 2;
	
	// PUBLIC PROPERTIES
	public String _FEED_URL = null;
	public int _RESULT_FEED_FOUND = 0;
	
	// PRIVATE PROPERTIES
	private boolean threadStop;
	private byte threadStatus = STATE_NOT_STARTED;
	
	public Handler HandlerOfCaller;
	  // ***************************
	    // Constructors
	    // ***************************
	    // Thread constructor
	Thread_FindFeed(Handler oHandler) 
	{
		HandlerOfCaller = oHandler;
	}
	
	public void run() 
    {
		threadStop = false;
		threadStatus = STATE_RUNNING;
		
		if(threadStop)
			//Message oMessage = HandlerOfCaller.obtainMessage();
			//oMessage.what = MESSAGE_PROGRESS;
        	//HandlerOfCaller.sendMessage(oMessage);
		try{
			if(Func_HTTP.FindFeeds(_FEED_URL)) {
				_RESULT_FEED_FOUND = 1;
				Log.d(_APP_TAG, "Feed(s) found");
			}else{
				_RESULT_FEED_FOUND = 0;
				Log.d(_APP_TAG, "No feed(s) found");
			}
			} catch (Exception e) {  }
			threadStatus = STATE_DONE;
      }
	
	public void StopThread()
	{
		threadStop = true;
	}
	  
	public byte GetStatus()
	{
		return threadStatus;
	}

	
 	}
